def path = this.args[0]

def homeDir = new File(path)

def data = [:]

def raw
def index
def readPeak = false
homeDir.eachFile{file->
    println 'file: '+file
    file.eachLine{line->
        if(line.startsWith('header=RawFile:')){
            def splitted = line.split(' ')
            raw = splitted[1]
            index = splitted[3]
            if(!data.containsKey(raw)){data.put(raw, [:])}
            if(!data[raw].containsKey(index)){data[raw].put(index, [:])}
            readPeak = true
        }else if(readPeak){
            readPeak = false
            if(data[raw][index].containsKey(line)){
                data[raw][index][line]++
            }else{
                data[raw][index].put(line, 1)
            }
        }
    }
}

println 'reading done'

data.each{rawFile,dv->
    dv.each{scanIndex,firstPeaks->
        if(firstPeaks.size()>1){
            println 'rawfile: '+rawFile+'\tindex: '+scanIndex
            firstPeaks.each{firstPeak,count->
                println '\tpeak: '+firstPeak+'\t'+count
            }
        }
    }
}